package com.itheima.d1_InetAddress;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 认识InetAddress中常见的方法
 */
public class InetAddressDemo1 {
    public static void main(String[] args) throws IOException {
        //1.获取本机的IP对象
        InetAddress ip1 = InetAddress.getLocalHost();
        System.out.println(ip1.getHostAddress());
        System.out.println(ip1.getHostName());

        //2.获取指定的IP对象
        InetAddress ip2 = InetAddress.getByName("www.baidu.com");
        System.out.println(ip2.getHostAddress());
        System.out.println(ip2.getHostName());

        //3.获取指定IP地址的IP对象
        InetAddress ip3 = InetAddress.getByName("127.0.0.1");
        System.out.println(ip3.getHostAddress());
        System.out.println(ip3.getHostName());

        //3.判断本机与对方主机是否互通
        boolean b = ip2.isReachable(5000);
        System.out.println(b);
        System.out.println("============");

        //4.获取IP地址
        InetAddress ip4 = InetAddress.getByName("192.168.38.77");
        System.out.println(ip4.getHostAddress());
        System.out.println(ip4.getHostName());
        boolean b2 = ip4.isReachable(5000);
        System.out.println(b2);

    }
}
